<template>
  <div>
    <el-dialog v-bind="dialogProps" :before-close="handleClose" :close-on-click-modal="false"
               :destroy-on-close="true" v-dialogDrag>
      <div>
        <h3 style="color:#009688;">缺陷隐患</h3>
      </div>
      <div style="width:100%;height:2px;background:#009688;margin-bottom: 10px;"></div>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm"
               size="small">
        <div>隐患信息-详情</div>
        <vxe-table border stripe ref="selectedEquip" height="200" :data="list.data">
          <vxe-column type="seq" title="序号" width="60" align="center"></vxe-column>
          <!-- <vxe-column field="equipTypeName" align="center" title="审核" minWidth="150"></vxe-column> -->
          <vxe-column field="defectStatusName" title="审核情况" align="center" minWidth="150"></vxe-column>
          <vxe-column field="equipName" title="隐患类型" align="center" minWidth="150"></vxe-column>
          <vxe-column field="projectName" title="隐患设备" align="center" minWidth="150"></vxe-column>
          <vxe-column field="methodName" title="隐患部位" align="center" minWidth="150"></vxe-column>
          <vxe-column field="methodName" title="隐患名称" align="center" minWidth="150"></vxe-column>
          <vxe-column field="methodName" title="隐患分类" align="center" minWidth="150"></vxe-column>
          <vxe-column field="methodName" title="隐患性质" align="center" minWidth="150"></vxe-column>
          <vxe-column field="methodName" title="隐患详细地点" align="center" minWidth="150"></vxe-column>
          <vxe-column field="methodName" title="隐患描述" align="center" minWidth="150"></vxe-column>
          <vxe-column field="methodName" title="缺陷发现日期" align="center" minWidth="150"></vxe-column>
          <vxe-column field="methodName" title="缺陷照片" align="center" minWidth="150"></vxe-column>
          <vxe-column field="methodName" title="现场是否已处理" align="center" minWidth="150"></vxe-column>
          <vxe-column field="methodName" title="处理后照片" align="center" minWidth="150"></vxe-column>
        </vxe-table>
        <div>缺陷信息-详情</div>
        <vxe-table border stripe ref="selectedEquip" height="200" :data="list.data">
          <vxe-column type="seq" title="序号" width="60" align="center"></vxe-column>
          <!-- <vxe-column v-if="ruleForm.taskStatus === '5' ? true : false" field="equipTypeName" align="center" title="审核" minWidth="150">
              <template v-slot="{ row }">
                  <el-button v-if="row.defectStatusCode === '1'" type="primary" size="mini" @click="handleClick(row, 1)">通过</el-button>
                  <el-button v-if="row.defectStatusCode !== '1'" type="info" size="mini" disabled>通过</el-button>
                  <el-button v-if="row.defectStatusCode === '1'" type="primary" size="mini" @click="handleClick(row, 2)">不通过</el-button>
                  <el-button v-if="row.defectStatusCode !== '1'" type="info" size="mini" disabled>不通过</el-button>
              </template>
          </vxe-column> -->
          <vxe-column field="defectStatusName" title="审核情况" align="center" minWidth="150">
          </vxe-column>
          <!-- <vxe-column field="defectDescription" title="缺陷程度描述" align="center" minWidth="150">
          </vxe-column> -->
          <vxe-column field="equipName" title="缺陷设备" align="center" minWidth="150">
          </vxe-column>
          <vxe-column field="defectParts" title="缺陷部位" align="center" minWidth="150">
          </vxe-column>
          <!-- <vxe-column field="methodName" title="缺陷名称" align="center" minWidth="150">
          </vxe-column> -->
          <vxe-column field="equipTypeName" title="设备类型名称" align="center" minWidth="150">
          </vxe-column>
          <!-- <vxe-column field="methodName" title="设备种类名称" align="center" minWidth="150">
          </vxe-column> -->
          <vxe-column field="partName" title="部件名称" align="center" minWidth="150">
          </vxe-column>
          <!-- <vxe-column field="methodName" title="部位名称" align="center" minWidth="150">
          </vxe-column>
          <vxe-column field="methodName" title="缺陷内容" align="center" minWidth="150">
          </vxe-column>
          <vxe-column field="methodName" title="缺陷级别" align="center" minWidth="150">
          </vxe-column> -->
          <vxe-column field="defectAddress" title="缺陷详细地点" align="center" minWidth="150">
          </vxe-column>
          <vxe-column field="defectDescription" title="缺陷描述" align="center" minWidth="150">
          </vxe-column>
          <!-- <vxe-column field="methodName" title="隐患发现日期" align="center" minWidth="150">
          </vxe-column> -->
          <vxe-column field="defectPictureIds" title="隐患照片" align="center" minWidth="150">
          </vxe-column>
          <vxe-column field="isHandle" title="现场是否已处理" align="center" minWidth="150">
          </vxe-column>
          <!-- <vxe-column field="methodName" title="处理后照片" align="center" minWidth="150">
          </vxe-column> -->
        </vxe-table>

        <div>
          <h3 style="color:#009688;">质量评价</h3>
        </div>
        <div style="width:100%;height:2px;background:#009688;margin-bottom: 10px;"></div>
        <el-row :gutter="16" justify="start">
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
            <el-form-item label="评价说明:" prop="appraiseContent">
              <el-input v-model="ruleForm.appraiseContent" placeholder="请输入评价说明" clearable
                        type="textarea"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="评价人:" prop="appraisePerson">
              <el-input v-model="ruleForm.appraisePerson" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="评价时间:" prop="appraiseTime">
              <el-date-picker v-model="ruleForm.appraiseTime" type="datetime" style="width:100%" clearable
                              disabled>
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="评价结论:" prop="appraiseStatus">
              <el-select v-model="ruleForm.appraiseStatus" placeholder="请选择评价结论" clearable
                         style="width: 100%" @change="appraiseStatusChange">
                <el-option v-for="item in appraiseStatusOptions" :key="item.value" :label="item.label"
                           :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>


        </el-row>

      </el-form>


      <span slot="footer" class="dialog-footer">
                <el-button @click="handleCancel()" :size="size" icon="fa fa-minus-square-o">取消</el-button>
                <el-button type="primary" @click="handleSubmit()" :size="size"
                           icon="fa fa-save (alias)">确定</el-button>
            </span>
    </el-dialog>
  </div>
</template>
<script>
import {qualityForm} from "../model/qualityForm";
import {workOrderManagement} from '@/api/equip/workOrderManagement.js'

export default {
  components: {},
  data() {
    return {
      dialogProps: {
        visible: false,
        title: "工单质量评价",
        width: "70%",
        top: "5px",
      },
      size: "medium",
      ruleForm: qualityForm.FormData,
      rules: qualityForm.rules,
      disabledForm: true,
      appraiseStatusOptions: [{label: '合格', value: '1'}, {label: '不合格', value: '2'},],
      xsnrShow: true,
      list: {
        data: []
      },
      row: {},

    };
  },
  methods: {
    showDialog(row, isDisabled) {
      this.row = row.row
      this.ruleForm.appraisePerson = 'admin'
      this.ruleForm.appraiseTime = moment().format('YYYY-MM-DD HH:mm:ss')
      this.dialogProps.visible = true;
      this.getTable()
    },
    basicsShow() {

      if (this.formShow) {
        this.formShow = false
        this.classFont = 'fa fa-caret-right'

      } else {
        this.formShow = true
        this.classFont = 'fa fa-caret-down'

      }

    },
    appraiseStatusChange(value) {
      this.ruleForm.appraiseStatusName = '';
      if (value) {
        let arr = this.appraiseStatusOptions.filter(item => {
          return item.value == value;
        })
        if (arr && arr.length > 0) {
          this.ruleForm.appraiseStatusName = arr[0].label;
        }
      }

    },


    //编辑渲染
    initData() {
    },
    getTable() {
      // workOrderManagement.getTaskEquipList(this.row.taskNo).then(res => {
      //     this.list.data = res.data
      // }).catch(err => {

      // })
      workOrderManagement.getTaskDefectList(this.row.taskNo).then(res => {
        this.list.data = res.data
      }).catch(err => {

      })
    },

    //确定
    handleSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          const queryParam = Object.assign({}, this.ruleForm)

          const params = [{
            id: this.row.id,
            taskStatus: '99',
            ...queryParam,
          }]
          workOrderManagement.updateData(params).then(res => {
            if (res.code === '200') {
              this.$message.success('评价成功')
              this.handleCancel()
              this.$emit('onSearch')
            }

          }).catch(err => {


          })


          this.handleCancel()
          this.dialogProps.visible = false;
        } else {
          return false;
        }
      });

    },
    //取消
    handleCancel() {
      this.$refs.ruleForm.resetFields()
      for (const k in this.ruleForm) {
        this.ruleForm[k] = ''
      }
      this.list = {
        data: [],
      }
      this.row = {}
      this.dialogProps.visible = false;
    },
    //确定关闭
    handleClose(done) {
      this.dialogProps.visible = false;
    },
  },
};
// 创建一个简单的超链接渲染

</script>
<style>
.el-dialog__footer {
  width: 100%;
  border-top: 1px solid #e8e8e8;
}
</style>
